from decimal import Decimal

students = []
while True:
    mark = True
    choice = input("选择你要进行的操作: 1.录入学生成绩 2.删除学生成绩 3.修改学生成绩 4.查询学生成绩 5.退出程序:")
    if choice == '1':
        name = input("请输入学生姓名:")
        num = input("请输入学号:")
        Chinese = Decimal(input("请输入语文成绩:"))
        English = Decimal(input("请输入英语成绩:"))
        Math = Decimal(input("请输入数学成绩:"))
        student = (name, num, Chinese, English, Math)
        students.append(student)
        print('录入成功！')
    elif choice == '2':
        if len(students) == 0:
            print('暂无学生信息，请先录入！')
        else:
            number = input("请输入要删除的学生学号:")
            for student in students:
                if student[1] == number:
                    students.remove(student)
                    print('已删除!')
                    mark = False
            if mark:
                print('未找到该学号的学生信息！')
    elif choice == '3':
        if len(students) == 0:
            print('暂无学生信息，请先录入')
        else:
            number = input('请输入需要修改信息的学生学号:')
            for student in students:
                if student[1] == number:
                    students.remove(student)
                    name = input("请输入新的学生姓名:")
                    num = input("请输入新的学号:")
                    Chinese = Decimal(input("请输入新的语文成绩:"))
                    English = Decimal(input("请输入新的英语成绩:"))
                    Math = Decimal(input("请输入新的数学成绩:"))
                    student = (name, num, Chinese, English, Math)
                    students.append(student)
                    mark = False
                    break
            if mark:
                print('未找到该学号的学生信息！')
    elif choice == '4':
        if len(students) == 0:
            print('暂无学生信息，请先录入')
        else:
            number = input('请输入需要查询的学生学号，全部查询输入all:')
            if number == 'all':
                print("所有学生成绩信息如下：")
                for student in students:
                    print(f"姓名: {student[0]} 学号: {student[1]} 语文成绩: {student[2]} 英语成绩: {student[3]} 数学成绩: {student[4]}")
            else:
                for student in students:
                    if student[1] == number:
                        score = student[2] + student[3] + student[4]
                        average = score / 3
                        print(f"姓名: {student[0]} 学号: {student[1]} 语文成绩: {student[2]} 英语成绩: {student[3]} 数学成绩: {student[4]}")
                        print(f"总分: {score} 平均分: {average:.2f}")
                        mark = False
                if mark:
                    print('未找到该学号的学生信息！')
    elif choice == '5':
        print("已经退出程序！")
        exit()
    else:
        print("输入无效！")
